<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%@ page import="org.springframework.web.context.support.WebApplicationContextUtils" %>
<%@ page import="org.springframework.context.ApplicationContext" %>
<%@ page import="com.sz.common.ICommonDAO" %>

<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";


String style1 = "width: 80;text-align:right;font-size: 12px;";
String style2 = "width: 120px";

ServletContext servletContext = request.getSession().getServletContext(); 
ApplicationContext context = WebApplicationContextUtils.getWebApplicationContext(servletContext);

String tmp = null;
tmp = request.getParameter("region");
String region = (tmp!=null) ? tmp : "";
String create_manager = request.getSession().getAttribute("userid").toString();
String region_id = request.getSession().getAttribute("regionid").toString();

ICommonDAO dao = (ICommonDAO) context.getBean("CommonDAO");
String Region_sql = "select region_id,REGION_NAME from region where parent_id = " + region_id;
List list_Area = dao.queryForList(Region_sql);
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
	<head>
	    <link href="<%= request.getContextPath() %>/css/main.css" rel="stylesheet" type="text/css" />
		<base href="<%=basePath%>">

		<title>商圈信息</title>
		<meta http-equiv="pragma" content="no-cache">
		<meta http-equiv="cache-control" content="no-cache">
		<meta http-equiv="expires" content="0">
		<meta http-equiv="keywords" content="addTicket">
		<meta http-equiv="description" content="商圈信息">
		
		<style type="text/css"> 
			@import "js/tableview/TableView.css";
    	</style>
	</head>
	
	<body>
		<script type="text/javascript" src="js/calendar.js"></script>
		<script type="text/javascript" src="js/jquery.js"></script>
		<script type="text/javascript" src="js/tableview/SortView.js"></script>
		<script type="text/javascript" src="js/tableview/PagerView.js"></script>
		<script type="text/javascript" src="js/tableview/TableView.js"></script>
		<script type="text/javascript" src="js/tableview/SelectorView.js"></script>
		<script type="text/javascript" src="js/tableview/PaperView.js"></script>
		<script type="text/javascript" src="js/utility.js"></script>
		<table width="100%" height="50px" border="0" cellpadding="0" cellspacing="0">
	  	 
	  	<tr>
		  	<td class="title0">商圈信息维护<br></td>
		  	
	  	</tr>
	  	</table>
	  	
		<table width="100%" height=120px border="0" cellpadding="0" cellspacing="0">
			<tr>
			  	<td style="<%=style1%>">行政区&nbsp;</td>
		  	<td>
		  		<select id="region" name="region" style="width:156px">
				  <option value="">请选择</option>
				   <%
				   String value = null;
				   String text = null;
				   boolean b = false;
				   %>
				   <%
				   for(int n = 0; n < list_Area.size(); ++n)
				   {    
					   Map map = (Map)list_Area.get(n);
					   value = map.get("REGION_ID").toString();
					   text = map.get("REGION_NAME").toString();
					   b = value.equals(region);
				   %>
				   <option <%if(b){%> selected="selected" <%}%>
				     value="<%=value%>"><%=text%>
				   </option>
				   <%}%>				   
				</select>
		  	</td>
			  	
	  
			  	<td style="<%=style1%>">商圈名称&nbsp;<br></td>		
			  	<td>
			  		<input  type="text" id="Group_Name" name="Group_Name"  style="<%=style2%>">
			  	</td>	
			  	
			  	<td style="<%=style1%>">商圈编码&nbsp;<br></td>		
			  	<td>
			  		<input  type="text" id="Group_Code" name="Group_Code"  style="<%=style2%>">
			  	</td>  	
				<td class="title0">
            		<input type="button" id="btn" name="btn" value="查询商圈" onclick="onClickQueryGroup()">
    
            		<input type="button" id="btn" name="btn" value="新增商圈" onclick="onClickAddGroup()">
	  			</td>	
		  	</tr>	
	  	</table>

	  	<div id="table_div" style= "width: 100%"></div>
		<div id="pager"></div>		
		<script type="text/javascript">
		
		var numPerPage = 10; //每页行数
		var paramValue = ""; //形如  "{STATUS:'1', CREATE_MANAGER:'1'}"
		var delparamValue = "";
		var methodCount = "queryGroupCount";
		var methodPage = "queryGroupPage";
		
		var table = new TableView('table_div');
		table.header = {
			GROUP_ID			: '商圈ID',
			NAME		        : '商圈名称',
			CODE		        : '商圈编码',
			REGION_NAME		    : '行政区划',
			MODIFY_GROUP		: '修改商圈信息'
		};		
		table.customDefine = {
				GROUP_ID			: '',
				NAME		        : '',
				CODE		        : '',
				REGION_NAME		    : '',
			    MODIFY_GROUP	    : ''
		};
				
		table.dataKey = 'GROUP_ID';
		table.count = false;
		table.title = false;
		table.display.filter = false;
		table.display.pager = false;
		table.pager.size = numPerPage;
		table.display.multiple = false;
		var pager = new PagerView('pager');
		pager.onclick = onPagerClick;
		pager.itemCount = 0;
		pager.size = numPerPage;
		
		table.render();
		pager.render();

		function queryGroup(pageNO, returnCount) {
  	  		var begin = (pageNO-1) * numPerPage + 1;
  	  		var end = pageNO * numPerPage;
  	  		var mc = returnCount==true ? methodCount : "";
  	  		var date = {
  	  			BEAN_METHOD 	: "BusinessGroupBMO.queryGroup",
  	  			PARAM_CLASS 	: "java.util.Map",
  	    	  	PARAM_VALUE 	: paramValue,
  	    	  	METHOD_COUNT 	: mc, //为空则不返回记录数
  	    	  	METHOD_PAGE 	: methodPage, //为空则不分页
  	    	  	PAGE_BEGIN 		: begin, //仅在METHOD_PAGE不为空时使用
  	    	  	PAGE_END 		: end
  	  	    };
  	  		$.ajax({
				type: "POST",
				url: "query.exec",
				//data: {id:'123'},
				data: date,
				datatype:"json",
				success: query_success,
				error: show_error
  	  		});

  			return true;
  			
  		}

  		function onPagerClick(pageNO) {
  			queryGroup(pageNO, "FLASE");
  		}
  		
  		//刷新当前页
  		function refreshCurrentPage() {
  			queryGroup(pager.index, "FLASE");
  		}

  		function query_success(data) {
  	  		var jdata = eval("(" + data + ")");
  	  		if(jdata.COUNT != null) { //有记录数返回  	  	  		
  	  	  		pager.itemCount = jdata.COUNT;
  	  	  		pager.size = numPerPage;  	  	  		
  	  	  		pager.render();
  	  		} 
		   var array = eval(jdata.LIST);
		   for(var i = 0; i < array.length; ++i) {
		   		//形如：<a href="javascript:" onclick="about()">modal</a>
		   	    url = "<input type=\"button\" value=\"修改\" onclick=\"OnModifyGroup('";
		   		url += array[i].GROUP_ID;		  
		   		url += "')\" />";
		   		array[i].MODIFY_GROUP = url;
		   }
		   table.clear();
		   table.addRange(array);
		}
  		function show_error(data) {
  			var err = "操作失败！\n";
  			err += "status：" + data.status + "\n";
  			err += "statusText：" + data.statusText;
  	  		alert(err);
 		}
 		
  		function onClickQueryGroup() 
  		{		
  			var tmp;
			paramValue = "{";
			
  			tmp = document.getElementById("region").value;
  			paramValue += " REGION_ID:'" + tmp;
			paramValue += "'";
			paramValue += ",";
			
  			tmp = document.getElementById("Group_Name").value;
  			paramValue += " NAME:'" + tmp;
  			paramValue += "'";
			paramValue += ",";
			
  			tmp = document.getElementById("Group_Code").value;
  			paramValue += " CODE:'" + tmp;
			paramValue += "'";
			paramValue += ",";			
  			paramValue += "}";
  				
  	  		pager.index = 1;
  	  		queryGroup(1, true);
  		}
  		
  		 function onClickAddGroup() {
  			var url = "<%=path%>";
  			url += "/businessgroup/addbusinessgroup.do?";
  			url += "&title=" + encodeURI(encodeURI("新增商圈信息"));
  			var param = "status:no;scroll:no;dialogWidth:1024px;dialogHeight:230px";
			window.showModalDialog(url, window, param);
 		}
 		
  		function OnModifyGroup(GROUP_ID) {
   			var url = "<%=path%>";
  			url += "/page/ModifyBusinessGroup.jsp?group_id=" + GROUP_ID;
  			var param = "status:no;scroll:no;dialogWidth:1024px;dialogHeight:230px";
			window.showModalDialog(url, window, param); 			
  		}
  		

 		function showMsg(data) {
  	  		alert(data);
 		}
 		
	</script>
	
	</body>
</html>
